import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDPayItemCard {
	/**id，svrCardIndex*/
	id,
	/**重置类型--0永久，1日，2周，3月*/
	type,
	/**持续时间(天数)--永久：-1*/
	time,
	/**邮件id*/
	mailid,
	/**校验离线当天是否有领取*/
	missionid,
	/**最大返回次数*/
	maxCount,
	/**标志//1为关闭购买 0为开放购买*/
	index,

	/**枚举数量*/
	EnumCount
}



export class CDPayItemCard{
	/**id，svrCardIndex*/
	public id: number;
	/**重置类型--0永久，1日，2周，3月*/
	public type: number;
	/**持续时间(天数)--永久：-1*/
	public time: number;
	/**邮件id*/
	public mailid: number;
	/**校验离线当天是否有领取*/
	public missionid: number;
	/**最大返回次数*/
	public maxCount: number;
	/**标志//1为关闭购买 0为开放购买*/
	public index: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDPayItemCard.id: return this.id;
			case E_CDPayItemCard.type: return this.type;
			case E_CDPayItemCard.time: return this.time;
			case E_CDPayItemCard.mailid: return this.mailid;
			case E_CDPayItemCard.missionid: return this.missionid;
			case E_CDPayItemCard.maxCount: return this.maxCount;
			case E_CDPayItemCard.index: return this.index;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDPayItemCard.id: this.id = v; break;
			case E_CDPayItemCard.type: this.type = v; break;
			case E_CDPayItemCard.time: this.time = v; break;
			case E_CDPayItemCard.mailid: this.mailid = v; break;
			case E_CDPayItemCard.missionid: this.missionid = v; break;
			case E_CDPayItemCard.maxCount: this.maxCount = v; break;
			case E_CDPayItemCard.index: this.index = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDPayItemCard> = new HashMap<number, CDPayItemCard>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDPayItemCard[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDPayItemCard();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].type = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].time = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].mailid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].missionid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].maxCount = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].index = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDPayItemCard{
		return this.datas ? this.datas.get(id) : null;
	}
}
